import json

import requests

# 模拟的浏览器版本
headers = {
    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
}
# 百度翻译的URL
url = 'https://fanyi.baidu.com/basetrans'
# 要发送的请求体
payload = {
    'query': 'every time go back',
    'from': 'en',
    'to': 'zh',
    'token': '448fc321127e7848096d94fe59eaf15e',
    'sign': '717278.922351'
}
# 字符串cookie（注意替换为自己浏览器中的cookies）
cookies_str = 'BIDUPSID=04AF705FF534F9830A6DEC13D73D12C9; PSTM=1602116049; BAIDUID=04AF705FF534F9830A513652D9FCB839:FG=1; FANYI_WORD_SWITCH=1; REALTIME_TRANS_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1604306521,1604374161; Hm_lvt_afd111fa62852d1f37001d1f980b6800=1604374887; H_WISE_SIDS=148078_146000_153767_160005_150967_152055_156286_150775_159609_148867_154804_153628_159533_159382_131862_160447_150772_151018_157261_157961_127969_153144_154174_155962_159065_158527_150346_155318_146732_158746_151831_131423_128699_153149_159701_155398_159450_107316_158054_160096_154190_158520_155344_155255_159955_157790_144966_159797_159950_154213_157814_158718_158640_156848_157965_147551_158910_156710_158415_154639_159157_154257_158686_159073_110085_157006; H_PS_PSSID=; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; rsv_i=0e42BriKvzBJBD0kHowyTPWvj3DRtV806U7v2AxoRH3p3uG4BOw5Vlln3mJF5LICIbz%2FOGL6xe%2B1aAOFN2jWoG2BRq1o8B0; FEED_SIDS=3000092_1; SE_LAUNCH=5%3A26739830; yjs_js_security_passport=9e4f385e1b36adfa8844893eb788a18c3195568c_1604390201_js; Hm_lpvt_afd111fa62852d1f37001d1f980b6800=1604390215; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1604390215'
# 将字符串转换cookie为字典
cookies_dict = {temp[:temp.find("=")]: temp[temp.find("=") + 1:] for temp in cookies_str.split("; ")}
print(cookies_dict)
r = requests.post(url=url, data=payload, headers=headers, cookies=cookies_dict)
ret = json.loads(r.content.decode())
print(ret['trans'][0]['dst'])
